#include<curses.h>
#include<stdlib.h>
#include "./otherCars.h"


int  other_cars(int laneSpeed, WINDOW *wnd, int row)
{
//returns the row it was last on	
	int	maxcol,
		maxrow,
		col=0,
//		lanecar,	//tells which lane will be open (no opponent car)
		rowTemp;
		
        getmaxyx(wnd, maxrow, maxcol);          //Gets the size of the window
	col = (maxcol/4.0)+3;               //set where the first colum starts
	
	if (row >= maxrow || row ==0)
	{
		row = 0;
		srand(time(NULL));	//set time seed to zero for random number
		lanecar = (rand() % 3 +1);	//get random number between 1 and 3
			
	}
	switch(lanecar)
	{
		case 1:		//dont put car in lane 1
			mvprintw(row, col+8, "CAR");		//put car in lane 2
			mvprintw(row, col+16, "CAR");		//put car in lane 3
			break;
		case 2:		//dont put car in lane 2
			mvprintw(row, col, "CAR");		//put car in lane 1
			mvprintw(row, col+16, "CAR");		//put car in lane 3
			break;
		case 3:		//dont put car in lane 3
			mvprintw(row, col, "CAR");		//put car in lane 1
			mvprintw(row, col+8, "CAR");		//put car in lane 2
			break;
	}
				
	refresh();
	usleep(laneSpeed);	//speed 

	mvprintw(row, col, "   ");  	//get rid of old cars
	mvprintw(row, col+8, "   ");
	mvprintw(row, col+16, "   ");
	refresh();
	row +=1;
			
	return row;
}

int drawLanesEasy(int laneSpeed, WINDOW *wnd, int row)          //draws moving lanes, speed Depends on laneSpeed varible
{
          int   maxcol,
                maxrow,
		col,
                rowTemp;

        getmaxyx(wnd, maxrow, maxcol);          //Gets the size of the window
        col=maxcol/4.0;				//col is where the fist col will be printed
        if (row >= maxrow)
        {
        	row = rowTemp;
                rowTemp-= 2;
                if (rowTemp >= maxrow)
                {
                	rowTemp = 0;
                }
	}

	mvprintw(row, col, "|\n \n");   //lane pattern
	mvprintw(row, col+8, "|\n \n"); //lane pattern
	mvprintw(row, col+16, "|\n \n");        //lane patternr
	mvprintw(row, col+24, "|\n \n");        //lane pattern
	refresh();
	usleep(10);              //lane speed
	
	return row;

}

